package org.db.ui;

import java.awt.Color;
import java.awt.Component;
import java.util.HashSet;
import java.util.Set;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class ColorTableCellRenderer extends DefaultTableCellRenderer {

	/**
	 * Färbung von Zellen einer Tabelle, wenn Widersprüche auftreten
	 */
	private static final long serialVersionUID = 4524511134450055809L;

	private static final Color highlightColor = Color.YELLOW;

	private static final Color highlightColor1 = Color.GREEN;

	private Set<Cell> cells2Highlight;

	private Set<Cell> cells2Highlight1;

	public ColorTableCellRenderer() {
		cells2Highlight = new HashSet<Cell>();
		cells2Highlight1 = new HashSet<Cell>();
		setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		Component c = super.getTableCellRendererComponent(table, value,
				isSelected, hasFocus, row, column);
		if (cells2Highlight.contains(new Cell(row, column))) {
			c.setBackground(highlightColor);
		} else if (cells2Highlight1.contains(new Cell(row, column))) {
			c.setBackground(highlightColor1);
		} else {
			c.setBackground(null);
		}
		return c;
	}

	public void highlightCell(int row, int column) {
		cells2Highlight.add(new Cell(row, column));
	}

	public void highlightCell1(int row, int column) {
		cells2Highlight1.add(new Cell(row, column));
	}

	public void reset() {
		cells2Highlight.clear();
	}

}
